<form action="{:sysuri()}" method="post" data-auto="true" class="layui-form layui-card" data-table-id="HouseTable">
    <div class="layui-card-body padding-left-40">

        <div class="layui-form-item">

            {if $super }
            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">{:lang('所属公司')}</label>
                <div class="layui-input-inline">
                    <select name="account_id" lay-search class="layui-select" lay-filter="account_id" id="account_id">
                        <option value=''>-- {:lang('全部')} --</option>
                        {foreach $account_list as $id => $name}
                        <option value="{$id}" {if isset($vo.account_id) && $id == $vo.account_id}selected{/if}>{$name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            {else/}
            <input type="hidden" name="account_id" id="account_id" value='{$vo.account_id|default=$adminUser.account_id}'>
            {/if}

            <div class="layui-inline">
                <label class="layui-form-label">{:lang('配置渠道')}</label>
                <div class="layui-input-inline">
                    <div id="xm-select-channel_ids" class="xm-select-channel_ids"></div>
                    <input name="channel_ids" id="channel_ids" type="hidden" value='{$vo.channel_ids|default=""}'>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">{:lang('国家')}</label>
                <div class="layui-input-inline">
                    <select name="country_id" lay-search  class="layui-select" required>
                        <option value=''>-- {:lang('请选择国家')} --</option>
                        {foreach $country_list as $item}
                        <option value="{$item.id}"  {if isset($vo.country_id) &&  $item.id == $vo.country_id}selected{/if}>{$item.coun_c_name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">{:lang('仓库中文名称')}</label>
                <div class="layui-input-inline">
                    <input name="warehouse_c_name" value='{$vo.warehouse_c_name|default=""}' required class="layui-input"  placeholder="{:lang('仓库中文名称')}">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">{:lang('仓库英文名称')}</label>
                <div class="layui-input-inline">
                    <input name="warehouse_e_name"  value='{$vo.warehouse_e_name|default=""}' class="layui-input" required  placeholder="{:lang('仓库英文名称')}">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">{:lang('仓库编码')}</label>
                <div class="layui-input-inline">
                    <input name="code" value='{$vo.code|default=""}' class="layui-input" required placeholder="{:lang('仓库编码')}">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">{:lang('仓库联系人')}</label>
                <div class="layui-input-inline">
                    <input name="contacts" value='{$vo.contacts|default=""}' class="layui-input" required placeholder="{:lang('仓库联系人')}">
                </div>
            </div>


            <div class="layui-inline">
                <label class="layui-form-label">{:lang('仓库联系电话')}</label>
                <div class="layui-input-inline">
                    <input name="house_phone" value='{$vo.house_phone|default=""}' class="layui-input" required placeholder="{:lang('仓库联系电话')}">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">{:lang('电子邮箱')}</label>
                <div class="layui-input-inline">
                    <input name="email" value='{$vo.email|default=""}' required class="layui-input" placeholder="{:lang('电子邮箱')}">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">{:lang('仓库邮政编码')}</label>
                <div class="layui-input-inline">
                    <input name="zip_code" value='{$vo.zip_code|default=""}' class="layui-input" required placeholder="{:lang('仓库邮政编码')}">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">{:lang('仓库 / 城市')}</label>
                <div class="layui-input-inline">
                    <input name="city" value='{$vo.city|default=""}' class="layui-input" required placeholder="{:lang('请输入城市')}">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">{:lang('仓库 / 洲')}</label>
                <div class="layui-input-inline">
                    <input name="district" value='{$vo.district|default=""}' class="layui-input" required placeholder="{:lang('请输入洲')}">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">{:lang('仓库 / 详细地址')}</label>
                <div class="layui-input-inline">
                    <textarea name="address" required placeholder="{:lang('请输入详细地址')}" class="layui-textarea">{$vo.address|default=""}</textarea>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">{:lang('仓库体积(m³)')}</label>
                <div class="layui-input-inline">
                    <input name="volume" value='{$vo.volume|default=""}' class="layui-input"  placeholder="{:lang('仓库体积')}">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">{:lang('排序')}</label>
                <div class="layui-input-inline">
                    <input name="sort" type="number" value='{$vo.sort|default=""}' class="layui-input"  placeholder="{:lang('排序')}">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">{:lang('全部状态')}</label>
                <div class="layui-input-inline">
                    <select name="status">
                        <option value=1 {if isset($vo.status) &&  $vo.status == 1}selected{/if}>{:lang('启用')}</option>
                        <option value=2 {if isset($vo.status) &&  $vo.status == 2}selected{/if}>{:lang('禁用')}</option>
                    </select>
                </div>
            </div>

        </div>
    </div>

    <div class="hr-line-dashed"></div>
    {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}

    <div class="layui-form-item text-center">
        <button class="layui-btn" type='submit'>{:lang('保存数据')}</button>
        {notempty name='vo.id'}
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="{:lang('确定要取消编辑吗？')}" data-close>{:lang('取消编辑')}</button>
        {/notempty}
    </div>
</form>
<script>
layui.use(['form', 'xmSelect'], function () {

    let xmSelectletObject = {
        el: '#xm-select-channel_ids',
        filterable: true,
        autoRow: true,
        toolbar: {
            show: true,
        },
        theme: {
            color: '#1E9FFF',
        },
        prop: {
            name: 'title',
            value: 'id',
        },
        initValue: JSON.parse('{$channel_ids_arr|raw}'),
        data: JSON.parse('{$channels|raw}'),
        on: data => {
            //arr:  当前多选已选中的数据
            let arr = data.arr
            // //change, 此次选择变化的数据,数组
            // let change = data.change;
            // //isAdd, 此次操作是新增还是删除
            // let isAdd = data.isAdd;
            // console.log(arr)
            // console.log(change)
            // console.log(isAdd)

            let valueArr = []
            arr.forEach(function(item) {
                valueArr.push(item.id)
            });
            let valueIds = valueArr.join(',')
            $('#channel_ids').val(valueIds)
        },
    }

    let xmSelectlet = xmSelect.render(xmSelectletObject)

    form.on('select(account_id)', function(data){
        // var elem = data.elem; // 获得 select 原始 DOM 对象
        // var value = data.value; // 获得被选中的值
        // var othis = data.othis; // 获得 select 元素被替换后的 jQuery 对象

        $('#channel_ids').val('')
        xmSelectlet.setValue([])

        $.ajax({
            url: '{:url("common/Ajax/getChannels")}',
            // cache: false,
            // processData: false, // 不处理数据
            // contentType: false, // 不设置内容类型
            type: 'POST',
            dataType: 'json',
            data: {'account_id':data.value},
        }).done(function(res) {
            // xmSelectletObject.initValue = []
            xmSelectletObject.data = res.data
            // console.log(xmSelectletObject)
            xmSelectlet = xmSelect.render(xmSelectletObject)
        })

    });
})
</script>